/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.view;

import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import org.model.Biblioteca;
import org.model.Pessoa;

/**
 *
 * @author Jack
 */
public class NovaBiblioteca extends javax.swing.JFrame {
private ArrayList<Biblioteca> ListaBibliotecass;
private ArrayList<Pessoa> Listapessoas;
public Biblioteca nova;
    /**
     * Creates new form NovaBiblioteca
     */
    public NovaBiblioteca(ArrayList<Biblioteca> ListaBibliotecass,ArrayList<Pessoa> Listapessoas) {
        
        this.ListaBibliotecass = ListaBibliotecass;
        this.Listapessoas=Listapessoas;
        initComponents();
        initkeys();
    }

    public ArrayList<Biblioteca> getListaBibliotecass() {
        return ListaBibliotecass;
    }

    public void setListaBibliotecass(ArrayList<Biblioteca> ListaBibliotecass) {
        this.ListaBibliotecass = ListaBibliotecass;
    }

    public ArrayList<Pessoa> getListapessoas() {
        return Listapessoas;
    }

    public void setListapessoas(ArrayList<Pessoa> Listapessoas) {
        this.Listapessoas = Listapessoas;
    }
    

 private void initkeys() {
     
       this.jTextFieldNovaBibli.addKeyListener(new KeyAdapter() {
            public void keyPressed(final KeyEvent e) {
                int key = e.getKeyCode();
                if (key == KeyEvent.VK_ENTER) {
                   btnSalvar.doClick();
                }
            }
        });
       
      //TECLA DE ATALHO Salvar(F3)
        Action actionTeclaF3 = new AbstractAction() {

    
            public void actionPerformed(ActionEvent arg0) {
                 btnSalvar.doClick();
            }
        };
       
             Action actionTeclaESC = new AbstractAction(){
           @Override
           public void actionPerformed(ActionEvent evt){
               dispose();
           }
       };
             
         //Variáveis de captura de teclas
        KeyStroke keyStrokeFechar = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
        KeyStroke keyStrokeF2 = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0);
        KeyStroke keyStrokeF3 = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);  
        KeyStroke keyStrokeF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);  
        KeyStroke keyStrokeF5 = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);  
        KeyStroke keyStrokeF6 = KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0); 
         

        InputMap inMap = btnSalvar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        inMap.put(keyStrokeF2, "Adicionar");
        inMap.put(keyStrokeF3, "Salvar");
        inMap.put(keyStrokeF4, "Cancelar");
        inMap.put(keyStrokeF5, "Modificar");
        inMap.put(keyStrokeF6, "Excluir");
        inMap.put(keyStrokeFechar, "Caralho");
        
        ActionMap amap = btnSalvar.getActionMap();
      //  amap.put("Adicionar", actionTeclaF2);
        amap.put("Salvar", actionTeclaF3);
       // amap.put("Cancelar", actionTeclaF4);
      //  amap.put("Modificar", actionTeclaF5);
     //   amap.put("Excluir", actionTeclaF6);
        amap.put("Caralho", actionTeclaESC);
        
             
             
       
 }

 
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        btnSalvar = new javax.swing.JButton();
        jTextFieldNovaBibli = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/gravar.png"))); // NOI18N
        btnSalvar.setText("Salvar (F3)");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        jTextFieldNovaBibli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNovaBibliActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Nome");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addComponent(jLabel2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(btnSalvar))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldNovaBibli, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(86, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldNovaBibli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addComponent(btnSalvar)
                .addContainerGap(64, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        // TODO add your handling code here:
        
       // System.out.println("ok");
      if(jTextFieldNovaBibli.getText().trim().isEmpty())
      JOptionPane.showMessageDialog(null, "Digite o Nome da biblioteca");
      else{
         nova = new Biblioteca(jTextFieldNovaBibli.getText());
         nova.setPessoas(this.Listapessoas);
         nova.imprimeStatus();
        this.getListaBibliotecass().add(nova);
        
        this.dispose();
      }
    
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void jTextFieldNovaBibliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNovaBibliActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNovaBibliActionPerformed


   /* Menu Principal não é necessário 
    public static void main(String args[]) {
          
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                try {
                    javax.swing.UIManager.setLookAndFeel(new SubstanceLookAndFeel());
                } catch (UnsupportedLookAndFeelException ex) {
                    Logger.getLogger(NovaBiblioteca.class.getName()).log(Level.SEVERE, null, ex);
                }
                    break;
                }
            }
        
 
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ArrayList<Biblioteca> teste = null;
               
               
                new NovaBiblioteca(teste).setVisible(true);
            }
        });
    }
    
    */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSalvar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextFieldNovaBibli;
    // End of variables declaration//GEN-END:variables
}
